package rs.mbs2.epics.server.session.dao.bean;

import java.util.List;

import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.persistence.Query;

import rs.mbs2.epics.server.entity.Tag;
import rs.mbs2.epics.server.session.dao.localinterface.TagDaoLocal;


@Stateless
@Local(TagDaoLocal.class)
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class TagDaoBean extends GenericDaoBean<Tag, Integer> implements TagDaoLocal {
	
	@Override
	public List<Tag> findTagsOnPhoto(Integer photoId) {
		Query q = em.createNamedQuery("findTagsOnPhoto");
		q.setParameter("photoId", photoId.toString());
		
		@SuppressWarnings("unchecked")
		List<Tag> result = (List<Tag>) q.getResultList();
		
		return result;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Tag> findTagByText(String text) {
		Query q = em.createNamedQuery("findTagByText");
		q.setParameter("tagText", text);
		
		return q.getResultList();
	}
	
}
